Java问题汇总
Maven相关问题
处理Maven远程仓库下载不到jar包问题
先去Maven Repository找到对应的依赖,并下载。
去下载目录下执行如下命令,注意替换掉-DgroupId,-DartifactId,-Dversion,-Dfile
mvn install:install-file -DgroupId=io.confluent -DartifactId=kafka-schema-registry-client -Dversion=4.1.0 -Dpackaging=jar -Dfile=kafka-schema-registry-client-4.1.0.jar
mvnw clean occurs Some Enforcer rules have failed
Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce
(enforce-versions) on project SIMI: Some Enforcer rules have failed. Look above for
specific messages explaining why the rule failed. -> [Help 1]
not solved! stackoverflow website
To skip enforcer (not always working)
mvn clean install -Denforcer.skip=true
To continue the build if error
mvn clean install -Denforcer.fail=false
./mvnw clean install -DskipDistribution=true -Denforcer.skip=true
MyBatis相关问题
SQL查询时 null值封装回int类型报 UncategorizedSQLException
将BO属性从int改为Integer类型
org.springframework.jdbc.UncategorizedSQLException: SqlMapClient operation;
uncategorized SQLException for SQL []; SQL state [null]; error code [0];
Mysql tinyint有毒
mysql 不要使用字段类型tinyint 可能你更新的1会变成49哦
MybatisPlus 出现 Invalid bound statement (not found) 异常
IDEA使用相关问题
idea terminal 中文乱码问题
# solve idea terminal Chinese garbled
export LANG="zh_CN.UTF-8"
export LC_ALL="zh_CN.UTF-8"
其他问题
动态数据源问题
如果所用的操作有事务,则需要在Dao层之前,对数据源进行设置,在Dao或者Mybatis-plus中的带dao的service都会切换数据源失效。
boolean改为Boolean可能遇到的问题
代码优化时,原始类型改成包装类型时,如果是Spring 注入的方式,注意默认值会有变化,boolean默认值为false,包装类为null,可能会造成空指针异常。
boolean 改为Boolean值,某些场景(netty 不响应请求)会有问题。
处理:给Boolean类赋值false
jackson序列化问题
错误信息:
Java 8 date/time type java.time.LocalDateTime not supported by default:
add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable
handling (through reference chain: java.util.ArrayList[0]->xxx.xxx.xxx.xxx.XxxxPo["updatetime"])
先排查是哪里报的
- 如果是可扩展Spring Boot的:直接扩展
ObjectMapper
@Configuration
public class JacksonConfig implements WebMvcConfigurer {
@Override
public void extendMessageConverters(final List<HttpMessageConverter<?>> converters) {
MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
objectMapper.registerModule(new JavaTimeModule());
messageConverter.setObjectMapper(objectMapper);
converters.add(0, messageConverter);
}
}
- 如果无法扩展,考虑跳过
Bean序列化步骤,比如用其实转化Bean为Map的方法 - 实在没有办法,改用
Fastjson或者Gjson
数据库连接池配置问题
使用Druid 连接池时, 配置参数 validationInterval必须小于 timeBetweenEvictionRunMillis, 保证数据库连接一直是可用的。
API接口规范
- 查询数据量、
- 入参参数检查、
- 响应报文中大整数,浮点数字段使用字符串类型
- 入参类型不为基本类型
协议
本作品代码部分采用 Apache 2.0协议 进行许可。遵循许可的前提下,你可以自由地对代码进行修改,再发布,可以将代码用作商业用途。但要求你:
- 署名:在原有代码和衍生代码中,保留原作者署名及代码来源信息。
- 保留许可证:在原有代码和衍生代码中,保留Apache 2.0协议文件。
- 署名:应在使用本文档的全部或部分内容时候,注明原作者及来源信息。
- 非商业性使用:不得用于商业出版或其他任何带有商业性质的行为。如需商业使用,请联系作者。
- 相同方式共享的条件:在本文档基础上演绎、修改的作品,应当继续以知识共享署名 4.0国际许可协议进行许可。